<template>
  <div class="ki-table">
    <div class="header">
      <h2 class="name">{{listName}}</h2>
      <div class="btns">
        <slot name="btn"></slot>
      </div>
    </div>
    <div class="table">
      <el-table :data="tableData" stripe style="width: 100%" border v-bind="childrenProps">
        <template v-if="isExpand">
          <el-table-column type="expand">
            <template #default="props">
              <h2 style="margin-left:50px;">申诉内容:</h2>
              <div v-html="props.row.content" style="padding:5px 50px">
              </div>
              <h2 style="margin-left:50px;">处理结果:</h2>
              <div v-html="props.row.feedback" style="padding:5px 50px;"></div>
            </template>
          </el-table-column>
        </template>
        <template v-if="isShowSelection">
          <el-table-column type="selection" align="center"></el-table-column>
        </template>
        <template v-if="isShowIndex">
          <el-table-column type="index" label="序号" width="80px" align="center"/>
        </template>
        <el-table-column  
          v-for="item in propList" 
          :key="item.prop"
          v-bind="item"
          align="center"
          show-overflow-tooltip
        >
          <template #default="scope">
            <slot :name="item.slotName" :item="scope.row">
              {{scope.row[`${item.prop}`]}}
            </slot>  
          </template>      
        </el-table-column>
      </el-table>
    </div>
    <div class="footer">
      <slot name="footer">
        <el-pagination
          layout="prev, pager, next" 
          :total="totalCount"
          hide-on-single-page
          @current-change="handlePageChange"
          v-if="isShowFooter"></el-pagination>
      </slot>
    </div>
  </div>
</template>

<script setup lang="ts">
import {IPropItem} from './type'
// interface IProps extends ITable{
interface IProps{
  propList: IPropItem[]
  listName: string
  isShowIndex?: boolean
  isShowSelection?: boolean
  isShowFooter?: boolean
  isExpand?:boolean
  childrenProps?:any
  tableData:any[]
  totalCount?:number
  page?:any
}
const props = withDefaults(defineProps<IProps>(),{
  isShowIndex:true,
  isShowSelection:true,
  isShowFooter:true,
  isExpand:false,
  totalCount:0,
  childrenProps:() => ({}),
  page:() =>  ({pagenum:1,pagesize:10})
})
interface IEmits {
  (e:'update:page',value:any) :void
}
const emits = defineEmits<IEmits>()
const handlePageChange = (pagenum:number) => {
  emits('update:page',{...props.page,pagenum:pagenum+""})
}
</script>

<style scoped lang="less">
.ki-table{
  .header{
    display: flex;
    justify-content: space-between;
    align-items: center;
    .name {
      margin-left:20px;
    }
    .btns{
      margin-right:20px;
    }
  }
  .footer{
   .el-pagination{
     justify-content: center;
     padding:40px 0;
   }
  }
}
</style>